package com.cy.pj.sys.controller;

import com.cy.pj.common.annotation.RequiredLog;
import com.cy.pj.common.bo.PageObject;
import com.cy.pj.common.vo.JsonResult;
import com.cy.pj.sys.entity.SysRole;
import com.cy.pj.sys.service.SysRoleService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Controller //@Controller+@ReponseBody
@RequestMapping("/role/")
public class SysRoleController {

	 @Autowired
	 private SysRoleService sysRoleService;
    private String prefix = "sys";

    @RequiresPermissions("sys:role:view")
    @GetMapping("/role_list")
    public String roleview()
    {
        return prefix + "/role_list";
    }


    @GetMapping("/role_edit")
    public String roleaddupdateview()
    {
        return prefix + "/role_edit";
    }
     @RequestMapping("doFindRoles")
     @ResponseBody
     public JsonResult doFindRoles() {

    	 return new JsonResult(sysRoleService.findObjects());
     }

     @RequestMapping("doFindObjectById")
     @ResponseBody
     public JsonResult doFindObjectById(Integer id) {
    	 return new JsonResult(sysRoleService.findObjectById(id));
     }

    @RequiresPermissions("sys:role:update")
     @RequestMapping("doUpdateObject")
     @ResponseBody
    @RequiredLog
     public JsonResult doUpdateObject(SysRole entity,Integer[]menuIds) {
        entity.setModifiedTime(new Date());
        sysRoleService.updateObject(entity,menuIds);
    	 return new JsonResult("update ok");
     }
    @RequiresPermissions("sys:role:add")
     @RequestMapping("doSaveObject")
     @ResponseBody
    @RequiredLog
     public JsonResult doSaveObject(SysRole entity,Integer[]menuIds) {
    	 sysRoleService.saveObject(entity, menuIds);
    	 return new JsonResult("save ok");
     }

    @RequiresPermissions("sys:role:delete")
     @RequestMapping("doDeleteObject")
     @ResponseBody
    @RequiredLog
     public JsonResult doDeleteObject(Integer id) {
    	 sysRoleService.deleteObject(id);
    	 return new JsonResult("delete ok");
     }

    @RequiresPermissions("sys:role:list")
     @RequestMapping("doFindPageObjects")
     @ResponseBody
     public JsonResult doFindPageObjects(String name,Integer pageCurrent) {
    	 PageObject<SysRole> pageObject=
    	 sysRoleService.findPageObjects(name, pageCurrent);
    	 return new JsonResult(pageObject);
     }

}




